﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Web.Mail;

namespace CentalineWeb.Common
{
    public class MailPush
    {

        public static void SendMail(string title, string content, string destination)
        {
            var objMailMessage = new MailMessage();
            objMailMessage.From = ConfigurationManager.AppSettings["sysmailAddress"];//源邮件地址
            objMailMessage.To = destination;//目的邮件地址，也就是发给我哈
            objMailMessage.Subject = title;//发送邮件的标题
            objMailMessage.Body = content;//发送邮件的内容
            objMailMessage.BodyFormat = MailFormat.Html;
            //接着利用sina的SMTP来发送邮件，需要使用Microsoft .NET Framework SDK v1.1和它以上的版本 
            //基本权限
            objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
            //用户名
            objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", ConfigurationManager.AppSettings["sysmailAddress"].Replace("@centaline.com.cn", ""));
            //密码
            objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", ConfigurationManager.AppSettings["sysmailPwd"]);
            //如果没有上述三行代码，则出现如下错误提示：服务器拒绝了一个或多个收件人地址。服务器响应为: 554 : Client host rejected: Access denied
            //SMTP地址 
            SmtpMail.SmtpServer = "mail.centaline.com.cn";
            //开始发送邮件
            SmtpMail.Send(objMailMessage);
        }
    }
}